<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('财报体检') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input
          v-model="queryParams.dealName"
          :placeholder="$t('项目名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('公司名称')" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          :placeholder="$t('公司名称')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">
          {{ $t("搜索") }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['company:pcw:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("上传财务数据") }}
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealPcwDataList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" min-width="260">
        <template slot-scope="scope">
          <el-link type="primary" class="link_a" @click="editPcwMedical(scope.row)">{{ scope.row.dealName }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="companyName" min-width="240">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/company/base/companyBaseHome',query:{companyId:scope.row.companyId}}"
            class="link_a"
          >{{ scope.row.companyName }}</router-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('负责人')" align="center" prop="personCharge" min-width="150" />
      <el-table-column :label="$t('最新财报')" align="center" prop="newPcwTitle" min-width="150" />
      <el-table-column :label="$t('报警次数')" align="center" prop="riskType" min-width="150">
        <template slot-scope="scope">
          <span class="riskSpan">
            <span class="risk-type-red" />
            <i>
              <el-link type="primary" class="link_a" @click="openWarning(scope.row,'red')">{{ scope.row.alarm }}</el-link>
            </i>
          </span>
          <span class="riskSpan">
            <span class="risk-type-yellow" />
            <i>
              <el-link type="primary" class="link_a" @click="openWarning(scope.row,'yellow')">{{ scope.row.warning }}</el-link>
            </i>
          </span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('监控关键条款')" align="center" prop="termsCount" min-width="150">
        <template slot-scope="scope">
          <el-link type="primary" class="link_a" @click="openTerms(scope.row)">{{ scope.row.termsCount }}</el-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 财报体检 -->
    <el-dialog :title="$t('财报体检')" :visible.sync="medicalFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogFormPcwMedical" append-to-body>
      <dealPcwMedicalTabs ref="dealPcwMedicalTabs" :company-id="companyId" />
    </el-dialog>
    <!-- 财报体检 -->
    <el-dialog :title="$t('监控数据')" :visible.sync="warnFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealPcwWarningList ref="dealPcwWarningList" />
    </el-dialog>
    <!-- 关键条款数据 -->
    <el-dialog :title="$t('关键条款监控')" :visible.sync="termsFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealPcwTermsList ref="dealPcwTermsList" />
    </el-dialog>
    <!-- 新增财务数据 -->
    <el-dialog :title="$t('财务数据上传')" :visible.sync="formOpen" width="30%" :close-on-click-modal="false" :lock-scroll="false" append-to-body>
      <pcw-data-main-upload ref="pcwDataMainUpload" outside @refresh="refresh" />
    </el-dialog>
  </div>
</template>

<script>
import dealPcwMedicalTabs from './dealPcwMedicalTabs.vue'
import dealPcwWarningList from './dealPcwWarningList.vue'
import dealPcwTermsList from './dealPcwTermsList'
import { dealPcwList } from '@/api/base/deal/dealBase'
import PcwDataMainUpload from '@/views/company/pcw/pcwDataMainUpload'

export default {
  components: {
    dealPcwMedicalTabs,
    PcwDataMainUpload,
    dealPcwWarningList,
    dealPcwTermsList
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 公司ID
      companyId: '',
      // 项目ID
      dealId: '',
      // 总条数
      total: 0,
      // 主表表格数据
      dealPcwDataList: [],
      // 弹出层标题
      title: '',
      // 新增财务数据是否显示弹出层
      formOpen: false,
      // 财报体检formOpen
      medicalFormOpen: false,
      // 监控页面
      warnFormOpen: false,
      // 关键条款页面
      termsFormOpen: false,
      // 查询参数
      queryParams: {
        dealName: undefined,
        companyName: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 获取存在财务数据的项目信息 */
    getList() {
      this.loading = true
      dealPcwList(this.queryParams).then(response => {
        this.dealPcwDataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        companyId: undefined,
        dealId: undefined,
        dealName: undefined,
        companyName: undefined,
        personCharge: undefined,
        normal: undefined,
        warning: undefined,
        alarm: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.pcwDataMainUpload.init()
      })
    },
    /** 财报体检 */
    editPcwMedical(row) {
      this.medicalFormOpen = true
      this.companyId = row.companyId
      this.dealId = row.dealId
    },
    refresh() {
      this.formOpen = false
      this.getList()
    },
    // 预警数据
    openWarning(row, type) {
      row.riskType = type
      this.warnFormOpen = true
      this.$nextTick(() => {
        this.$refs.dealPcwWarningList.init(row)
      })
    },
    // 监控关键条款
    openTerms(row) {
      this.termsFormOpen = true
      this.$nextTick(() => {
        this.$refs.dealPcwTermsList.init(row)
      })
    }
  }
}
</script>
